const MerchantInfo = require('./MerchantInfo');
const ProductInfo = require('./ProductInfo');
const Member = require('./Member');
const Manager = require('./Manager');
const CustomInfo = require('./CustomInfo');
const OrderInfo = require('./OrderInfo');
const ReceiptInfo = require('./ReceiptInfo');

// 成员和负责人的关联
Member.belongsTo(Manager, { foreignKey: 'manager_id' });
Manager.hasMany(Member, { foreignKey: 'manager_id' });

// 负责人和用户的关联
Manager.belongsTo(Member, { foreignKey: 'user_id' });
Member.hasOne(Manager, { foreignKey: 'user_id' });

// 定制信息的关联
CustomInfo.belongsTo(ProductInfo, { foreignKey: 'product_id' });
CustomInfo.belongsTo(Member, { foreignKey: 'user_id' });

// 订单信息的关联
OrderInfo.belongsTo(MerchantInfo, { 
  foreignKey: ['merchant_name', 'merchant_taobao_id'],
  targetKey: ['merchant_name', 'taobao_id']
});
OrderInfo.belongsTo(Manager, { foreignKey: 'manager_id' });

// 签领信息的关联
ReceiptInfo.belongsTo(Member, { foreignKey: 'user_id' });

module.exports = {
  MerchantInfo,
  ProductInfo,
  Member,
  Manager,
  CustomInfo,
  OrderInfo,
  ReceiptInfo
}; 